home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / news / inn1.000 / inn1.4sec-linux-src.tar / inn / nnrpd / loadave.c < prev    next >
C/C++ Source or Header  |  1993-01-29  |  1KB  |  59 lines

  1. /*  $Revision: 1.3 $
  2. **
  3. */
  4. #include "nnrpd.h"
  5. #if    NNRP_LOADLIMIT > 0
  6. #include <nlist.h>
  7. STATIC struct nlist NameList[] = {
  8.     { "_avenrun" },
  9. #define    X_AVENRUN    0
  10.     { NULL }
  11. };
  12.  
  13.  
  14. /*
  15. **  Get the current load average as an integer.
  16. */
  17. int
  18. GetLoadAverage()
  19. {
  20.     int        fd;
  21.     int        oerrno;
  22. #if    defined(FSCALE)
  23.     long    avenrun[3];
  24. #else
  25.     double    avenrun[3];
  26. #endif    /* defined(FSCALE) */
  27.  
  28.     fd = open("/dev/kmem", 0, 0);
  29.     if (fd < 0)
  30.     return -1;
  31.  
  32. #if    defined(HPUX)
  33.     (void)nlist("/hp-ux", NameList);
  34. #else
  35. #if    defined(SUNOS5)
  36.     (void)nlist("/dev/ksyms", NameList);
  37. #else
  38.     (void)nlist("/vmunix", NameList);
  39. #endif    /* defined(SUNOS5) */
  40. #endif    /* !defined(HPUX) */
  41.     if (NameList[0].n_type == 0
  42.      || lseek(fd, (off_t) NameList[X_AVENRUN].n_value, SEEK_SET) == -1
  43.      || read(fd, (char *)avenrun, sizeof avenrun) != sizeof avenrun) {
  44.     oerrno = errno;
  45.     (void)close(fd);
  46.     errno = oerrno;
  47.     return -1;
  48.     }
  49.  
  50.     (void)close(fd);
  51.  
  52. #if    defined(FSCALE)
  53.     return (int)(avenrun[0] + FSCALE / 2) >> FSHIFT;
  54. #else
  55.     return (int)(avenrun[0] + 0.5);
  56. #endif    /* defined(FSCALE) */
  57. }
  58. #endif    /* NNRP_LOADLIMIT > 0 */
  59.